<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('dubbo接口 字段参数选择页面')" />
	<link th:href="@{/css/common.css}" rel="stylesheet"/>
	<link th:href="@{/css/choose_data_map.css}" rel="stylesheet"/>
</head>
	<body>
		<div class="wrapper wrapper-content ">
			<div class="content">
				<div class="search-bg">
					<div class="search-img" id="searchDiv"></div>
					<input type="text" class="search" id="searchValue">
				</div>
				<table class="table table-hover" style = "margin-top:10px;">
					<tbody></tbody>
				</table>
				<input type="hidden" id="tableInfo"/>
				<input type="hidden" id="tableIds" th:value="${tableIds}"/>
			</div>
		</div>
	</body>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "table/table";
		$(function () {
			$("#searchDiv").click(function() {
				loadTable();
			});

			loadTable();
		})

		function loadTable() {
			var config = {
				url: prefix + "/list",
				type: "post",
				dataType: "json",
				data: "searchValue="+$("#searchValue").val()+"&excludeIds=" + $("#tableIds").val(),
				beforeSend: function () {
					$.modal.loading("正在处理中，请稍后...");
				},
				success: function(result) {
					$("table tbody").empty();
					$.modal.closeLoading();
					if (result.code == web_status.SUCCESS) {
						if (result.rows && result.rows.length > 0) {
							var data = {};
							data.list = result.rows;
							var paramsTplHtml = $("#paramsTpl").html();
							laytpl(paramsTplHtml).render(data, function (html) {
								$("table tbody").append(html);
							});

						}
					} else if (result.code == web_status.WARNING) {
						$.modal.alertWarning(result.msg)
					} else {
						$.modal.alertError(result.msg);
					}
				}
			};
			$.ajax(config);
		}

		function checkboxClick() {
			var value = '';
			var count = 0;
			$('table').find(':checkbox').each(function(){
				if ($(this).is(":checked")) {
					count ++;
					value = value + $(this).val() + "=" + $(this).attr('data') + ',';
				}
			});
			$("#tableInfo").val(value);
			$("#selectTable",window.parent.document).text(count);
		}
	</script>

<script id="paramsTpl" type="text/template">
		{{# layui.each(d.list, function(index, a){ }}
		<tr>
			<td><input data="{{a.tableName}}" onclick="checkboxClick()" type="checkbox" value="{{a.id}}"></td>
			<td>{{a.tableName}}</td>
			<td>{{a.tableEnName}}</td>
		</tr>
		{{# }); }}
</script>
</html>
